/**
 * 
 */
package intellitrends.adaptors;

import java.util.ArrayList;

import intellitrends.activities.R;
import intellitrends.data.EatOutData;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class EatOutAdaptor extends ArrayAdapter<EatOutData> {

	private ArrayList<EatOutData> items;
	
	public EatOutAdaptor(Context context, int textViewResourceId,ArrayList<EatOutData> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		this.setItems(objects);
	}

	public ArrayList<EatOutData> getItems() {
		return items;
	}

	public void setItems(ArrayList<EatOutData> items) {
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		//return super.getView(position, convertView, parent);
		View v = convertView;
		
		if ( v == null ){
			Context cxt = this.getContext();
			LayoutInflater vi = (LayoutInflater)cxt.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.eatoutrow, null);
		}
		
		EatOutData eatout = this.items.get(position);
		if ( eatout != null ){
			TextView tvName = (TextView) v.findViewById(R.id.txtName);
			TextView tvType = (TextView) v.findViewById(R.id.txtType);
			TextView tvAddress = (TextView) v.findViewById(R.id.txtAddress);
			TextView tvDistance = (TextView) v.findViewById(R.id.txtDistance);
			
			if ( tvName != null ){
				tvName.setText(eatout.getEatoutName());
			}
			
			if ( tvType != null ){
				tvType.setText(eatout.getEatoutType());
			}
			
			if ( tvAddress != null ){
				tvAddress.setText(eatout.getEatoutAddress());
			}

			if ( tvDistance != null ){
				tvDistance.setText(""+eatout.getDistance());
			}
		}
		return v;
	}
	
}
